// miniprogram/pages/main/dream-list-page/dream-list-page.js
const util = require('../../../util/common.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isReleasing:false,
    commenting: false,
    topBarHeight: app.globalData.systemInfo.statusBarHeight + wx.getMenuButtonBoundingClientRect().height + (wx.getMenuButtonBoundingClientRect().top - app.globalData.systemInfo.statusBarHeight) * 2,
    statusBarHeight: app.globalData.systemInfo.statusBarHeight,
    showSearchPanel: "none",
    searchBarBgColor: "white",
    icons: {
      filter: '',
      search: '',
      release: ''
    },
    //梦的数据列表
    dreams:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(JSON.stringify(app.globalData))
    this.setData({
      userInfo: app.globalData.user.info
    })
    let dreams = this.data.dreams;
    for(let i = 0;i<5;i++){
      dreams.push({
        // 分享的日期
        date: {
          year: '2021',
          month: i+1,
          day: '18',
          time: '00:18',
          weekday: '周 五'
        },
        // 分享人的信息
        author: {
          nickname: 'blue',
          sex: 1,
          avatarUrl: 'https://thirdwx.qlogo.cn/mmopen/vi_32/B5YoA7b4Aee2BCqibkQ85kgyr4icM7pAs3yXSDyygsmzHeMXuQlgXYa0rzKibBpUl1MiazJsVJKOAuYic7X70YD9mMg/132'
        },
        //梦的相关信息
        dreamInfo: {
          content: '梦到自己变成了🐖',
          like: 0,
          comment: 0,
          tag: '糟糕',
          releaseTag: '刚刚'
        }
      })
    }
    this.setData({
      dreams
    })
  },
  //发布梦
  releaseDream:function(){
    this.setData({
      isReleasing:true
    })
  },
  //上拉加载更多梦
  loadMoreDreams:function(e){
    // e.detail.success();
    this.setData({
      isLoadingMoreDreams:true
    })
    
    setTimeout(() => {

      let dreams = this.data.dreams;
      for (let i = 0; i < 5; i++) {
        dreams.push({
          // 分享的日期
          date: {
            year: '2021',
            month: i + 1,
            day: '18',
            time: '00:18',
            weekday: '周 五'
          },
          // 分享人的信息
          author: {
            nickname: 'blue',
            sex: 1,
            avatarUrl: 'https://thirdwx.qlogo.cn/mmopen/vi_32/B5YoA7b4Aee2BCqibkQ85kgyr4icM7pAs3yXSDyygsmzHeMXuQlgXYa0rzKibBpUl1MiazJsVJKOAuYic7X70YD9mMg/132'
          },
          //梦的相关信息
          dreamInfo: {
            content: '梦到自己变成了🐖',
            like: 0,
            comment: 0,
            tag: '糟糕',
            releaseTag: '刚刚'
          }
        })
      }
      this.setData({
        dreams
      })
    e.detail.success();
      this.setData({
      isLoadingMoreDreams: false
    })},2000)
  },
  //刷新列表
  refreshDreamList:function(e){
    setTimeout(()=>{
      e.detail.fail();
    },1000)
  },
  //切换评论状态
  toggleComment: function(e) {
    let data = e.detail;
    console.log(JSON.stringify(e));
    this.setData({
      commenting: data
    });
  },
  showSearchPanel: function() {
    //显示搜索框
    this.setData({
      showSearchPanel: "block"
    })
    //更改顶部栏颜色
    this.setData({
      searchBarBgColor: "#84A6B9"
    })
  },
  dismissSearchPanel: function() {
    this.setData({
      showSearchPanel: "none"
    })
    //更改顶部栏颜色
    this.setData({
      searchBarBgColor: "white"
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})